
export function JsonToMarkdown(nodeJson:any) {

  
  // 2. 自定义转换逻辑
  function nodeToMarkdown(node:any) {
    if (node.type === 'text') {
      let text = node.text || ''
      // 处理 marks (粗体、斜体等)
      if (node.marks) {
        node.marks.forEach((mark:any) => {
          if (mark.type === 'bold') text = `**${text}**`
          if (mark.type === 'italic') text = `_${text}_`
          if (mark.type === 'code') text = `\`${text}\``
          if (mark.type === 'link') text = `[${text}](${mark.attrs.href})`
        })
      }
      return text
    }
    
    // 处理块级元素
    let content = node.content?.map(n => nodeToMarkdown(n)).join('') || ''
    
    switch (node.type) {
      case 'paragraph':
        return `${content}\n\n`
      case 'heading':
        return `${'#'.repeat(node.attrs.level)} ${content}\n\n`
      case 'bulletList':
        return node.content.map(n => `- ${nodeToMarkdown(n)}`).join('')
      case 'orderedList':
        return node.content.map((n, i)  => `${i + 1}. ${nodeToMarkdown(n)}`).join('')
      case 'listItem':
        return `${content}\n`
      case 'codeBlock':
        return `\`\`\`${node.attrs.language || ''}\n${content}\n\`\`\`\n\n`
      default:
        return content
    }
  }

  // 3. 转换整个选中内容
  return nodeJson.content.map((node:any) => nodeToMarkdown(node)).join('')
}